package com.decent.ejfadmin.report.controller;

import com.decent.ejfadmin.auth.ApiVerification;
import com.decent.ejfadmin.report.response.DouLeFaceValueTotal;
import com.decent.ejfadmin.report.response.DouLeProductTypeTotal;
import com.decent.ejfadmin.report.response.DouLeProvinceTotal;
import com.decent.ejfadmin.report.service.CollectCardApiStockReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.List;

/**
 * 给易服务统计的接口
 *
 * @author weicx
 * @date 2019/03/12
 */
@RestController
@Slf4j
@RequestMapping("CollectCardStockReport")
public class CollectCardApiStockReportController {
    @Autowired
    private CollectCardApiStockReportService collectCardApiStockReportService;

    /**
     * 收卡卡密库存统计
     *
     * @return 总数
     */
    @RequestMapping("douLeProductTypeTotal")
    @ApiVerification
    public List<DouLeProductTypeTotal> collectCardStockReport() {
        try {
            return collectCardApiStockReportService.collectCardStockReport();
        } catch (Exception e) {
            log.warn("收卡卡密库存面值省份统计[{}]",e);
            return Collections.emptyList();
        }
    }

    /**
     * 收卡卡密库存面值省份统计
     *
     * @param productType 运营商
     * @return
     */
    @RequestMapping("douLeProvinceTotal")
    @ApiVerification
    public List<DouLeProvinceTotal> collectCardStockPricePage(Integer productType) {
        try {
            return collectCardApiStockReportService.collectCardStockPricePage(productType);
        } catch (UnsupportedEncodingException e) {
            log.warn("[{}]收卡卡密库存面值省份统计[{}]",productType,e);
            return Collections.emptyList();
        }
    }

    /**
     * 收卡卡密库存折扣省份统计
     *
     * @param productType 运营商
     * @param province    省份
     * @param faceValue   面值
     * @return
     */
    @RequestMapping("douLeFaceValueTotal")
    @ApiVerification
    public List<DouLeFaceValueTotal> collectCardPriceReport(Integer productType, String province, Integer faceValue) {
        try {
            return collectCardApiStockReportService.collectCardPriceReport(productType, province, faceValue);
        } catch (UnsupportedEncodingException e) {
           log.warn("[{}][{}][{}]收卡卡密库存折扣省份统计异常[{}]",productType,province,faceValue,e);
           return Collections.emptyList();
        }
    }
}
